﻿<?php
@session_start();

require_once("../../class/mysql.class.php");

  $obj = new Mysql();
  
  $obj -> set_table('user_login');
  $obj -> set_colone("(`*`)");
  $obj -> set_variables(" id_login = '" . $_SESSION["id"] . "' ");
  $user = $obj -> select_enregistrement();

	$ref_article = $_REQUEST["ref_article"]; 
	$type_id = addslashes($_REQUEST["id_type"]); 
	//$description = addslashes($_REQUEST["description"]); 
	$designation= addslashes($_REQUEST["designation"]);
	$emplacement_id = addslashes($_REQUEST["id_emplacement"]); 
	$prix = addslashes($_REQUEST["prix"]); 
	//$id_type_monnaie = addslashes($_REQUEST["type_monnaie"]; 
	$commentaire = addslashes($_REQUEST["comment"]); 
	$id_fournisseur = 0; 
	$quantite = 0;
	$qte_min = addslashes($_REQUEST["qte_min"]);
	$id_unit_stockage = addslashes($_REQUEST["id_unit"]); 
	$id_user = $user['id_login'];
	
if ($_FILES['photo_article']['error']) 
		{     
				  switch ($_FILES['photo_article']['error']){     
						   case 1: // UPLOAD_ERR_INI_SIZE     
						   echo"Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !";     
						   break;     
						   case 2: // UPLOAD_ERR_FORM_SIZE     
						   echo "Le fichier dépasse la limite autorisée dans le formulaire HTML !"; 
						   break;     
						   case 3: // UPLOAD_ERR_PARTIAL     
						   echo "L'envoi du fichier a été interrompu pendant le transfert !";     
						   break;     
						   case 4: // UPLOAD_ERR_NO_FILE     
						   echo "Le fichier que vous avez envoyé a une taille nulle !"; 
						   break;     
							}
			$photoName = 'article_pic/'.date('Y').'/'.date('m').'/'.date('d').'/'.$ref_article.'_'.$_FILES['photo_article']['name'].'/nofile.jpg';		
			}     
			elseif (isset($_FILES['photo_article']['tmp_name'])&&($_FILES['photo_article']['error'] == 0)) 
			{     
				$chemin_destination = '../../article_pic/'.date('Y').'/'.date('m').'/'.date('d').'/';
				$ext = explode('.',$_FILES['photo_article']['name']);
				$extension = $ext[1];					
				move_uploaded_file($_FILES['photo_article']['tmp_name'], $chemin_destination.$ref_article.'_'.$_FILES['photo_article']['name']);
				$photoName = 'article_pic/'.date('Y').'/'.date('m').'/'.date('d').'/'.$ref_article.'_'.$_FILES['photo_article']['name'];		
			}
		//$photoName = $_FILES['photo_article']['name'];
		
		$req="SELECT * FROM `st_article` WHERE ref_article='".$ref_article."'";
		$obj = new Mysql ();
		$resultat = mysql_query($req);
		echo mysql_num_rows($resultat);
		if(mysql_num_rows($resultat)<1)
		
		{
		
			$sql = "INSERT INTO `st_article` (`id_article`, `ref_article`,`designation`, `id_user`, `id_type`, `id_lieu`, `id_fournisseur`, `id_unite_stockage`, `last_modif`, `prix`, `commentaire`, `date_add`, `Quantite`, `Qte_min`, `photo_name`, `last_user_modif`) 
			VALUES 
			('', '".$ref_article."','".$designation."', '".$id_user."', '".$type_id."', '".$emplacement_id."', '".$id_fournisseur."', '".$id_unit_stockage."', '".date('m/d/Y')."', '".$prix."', '".$commentaire."', '".date('m/d/Y')."', '".$quantite."', '".$qte_min."', '".$photoName."', '".$id_user."')";
			echo $sql;
			mysql_query($sql);
			/*if(mysql_query($sql)){
				$sqlEntree = "INSERT INTO `st_attr_entree` (`id_entree`, `id_article`, `id_fournisseur`, `qte`, `prix`,
				`ajouter_par`, `date_add`,`last_modif`,`last_user_modif`)  VALUES 
						('', '".mysql_insert_id()."', '".$id_fournisseur."', '".$quantite."',
						'".$prix."', '".$id_user."','".date('m/d/Y')."','".date('m/d/Y')."','".$id_user."')";
						mysql_query($sqlEntree);
			*/
			
		header('location:../../list_article.php?action=added&ref='.$ref_article.'&page=list_article');
			
		}
		else
		{
			header('location:../../list_article.php?action=addedError&ref='.$ref_article.'&page=list_article');
		}
	

